package com.ssm.gbq.controller;

import com.ssm.gbq.model.Doctor;
import com.ssm.gbq.service.DoctorService;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 医生 控制器
 * @author yanqb
 * 2019年6月13日16:12:59
 */
@Controller
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired 
    private DoctorService doctorService;
    
    /**
     * 获取医生列表
     */
    @ResponseBody
    @RequestMapping(value = "/openDoctorTable", method = RequestMethod.POST)
    public HashMap<String, Object> openDoctorTable(String nameOrPhone,int pageSize,int currentPage){
        HashMap<String,Object> result = new HashMap<>();
        PageBounds<Doctor> pageBounds = doctorService.openDoctorTable(nameOrPhone, currentPage,pageSize);
        result.put("data", pageBounds);
        return result;
    }

    /**
     * 模糊查询医生名字
     */
    @ResponseBody
    @RequestMapping(value = "/searchDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> searchDoctor(String nameOrPhone){
        HashMap<String,Object> result = new HashMap<>();
        List<Doctor> doctors = doctorService.searchDoctor(nameOrPhone);
        result.put("doctors", doctors);
        return result;
    }

    /**
     * 添加医生
     */
    @ResponseBody
    @RequestMapping(value = "/addDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> addDoctor(Doctor doctor){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.addDoctor(doctor);
        return result;
    }

    /**
     * 删除医生
     */
    @ResponseBody
    @RequestMapping(value = "/delDoctorById", method = RequestMethod.POST)
    public HashMap<String, Object> delDoctorById(Integer[] ids){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.delDoctorById(Arrays.asList(ids));
        return result;
    }

    /**
     * 修改医生
     */
    @ResponseBody
    @RequestMapping(value = "/updateDoctor", method = RequestMethod.POST)
    public HashMap<String, Object> updateDoctor(Doctor doctor){
        HashMap<String,Object> result = new HashMap<>();
        doctorService.updateDoctor(doctor);
        return result;
    }
}
